<%@ page language="java" pageEncoding="UTF-8" %>
<%@page import="cn.com.wxd.common.system.SystemInfoUtil" %>
<%@page import="cn.com.wxd.util.website.WebsiteInfo" %>
<%@page import="cn.com.wxd.util.service.ProjectInfo" %>
<%@page import="cn.com.wxd.util.RequestUtil" %>
<%@page import="cn.com.wxd.service.weather.Weatherbean" %>
<%@page import="cn.com.wxd.util.service.WebUtil" %>
<%@ page import="cn.com.wxd.entity.website.WebInfo" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%
    String path = request.getContextPath();
    String basePath =
            request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;

    Weatherbean weatherBean = WebUtil.getWeather(request);
    WebInfo webInfo = (WebInfo) request.getAttribute("webInfo");
%>
<!DOCTYPE html>
<head>
    <base href="<%=basePath %>">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="author" content="WangXuDong">
    <link rel="stylesheet" type="text/css" href="static/admin/lib/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="static/admin/css/theme.css">
    <link rel="stylesheet" type="text/css" href="static/admin/lib/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="static/admin/css/main.css">
    <link rel="stylesheet" type="text/css" href="static/admin/lib/radialIndicator/radialindicator.css">
    <script type="text/javascript" src="static/admin/lib/radialIndicator/radialIndicator.min.js"></script>
</head>
<body class="">
<div class="header">

    <div class="stats">
        <%
            if (weatherBean != null) {
        %>
        <p class="stat" style="margin-left: 0px;">
            <img alt="<%=weatherBean.getStateDetailed() %>" style="width:40px;"
                 src="<%=weatherBean.getWeatherImage()%>"/>
        </p>
        <p class="stat" style="line-height: 3em;color: #4A79D1;margin-left: 0px;">
            <%= weatherBean.getStateDetailed()%>
        </p>
        <%
            }
        %>
    </div>
</div>

<ul class="breadcrumb">
    <li><a href="#">首页</a> <span class="divider">/</span></li>
    <li class="active">网站信息</li>
</ul>

<div class="container-fluid">
    <div class="row-fluid">


        <div class="row-fluid">

            <div class="alert alert-info">
                <button type="button" class="close" data-dismiss="alert">×</button>
                <strong>温馨提示:</strong>&nbsp;&nbsp;&nbsp;<a id="prompt" href="#"></a>
            </div>

            <div class="block">
                <a href="#page-stats" class="block-heading" data-toggle="collapse">最新统计数据</a>
                <div id="page-stats" class="block-body collapse in">

                    <div class="stat-widget-container">
                        <div class="stat-widget" style="width: 20%;">
                            <div class="stat-button">
                                <p class="title">
                                    <%=webInfo.getTodayVisiVol() %>次
                                    <span id="fangwen"></span>
                                </p>
                                <p class="detail">今日访问量统计</p>
                            </div>
                        </div>

                        <div class="stat-widget" style="width: 20%;">
                            <div class="stat-button">
                                <p class="title">
                                    <%=webInfo.getTodayVisiVol() %> 次
                                    <span id="fangwen"></span>
                                </p>
                                <p class="detail">总访问量统计</p>
                            </div>
                        </div>

                        <div class="stat-widget" style="width: 20%;">
                            <div class="stat-button">
                                <p class="title">
                                    <%=webInfo.getTotaluserNum() %> 人</p>
                                <p class="detail">用户数量</p>
                            </div>
                        </div>

                        <div class="stat-widget" style="width: 20%;">
                            <div class="stat-button">
                                <p class="title">
                                    <%=webInfo.getTotalArticleNum() %> 篇</p>
                                <p class="detail">文章数量</p>
                            </div>
                        </div>

                        <div class="stat-widget" style="width: 20%;">
                            <div class="stat-button">
                                <p class="title">
                                    <%=webInfo.getOnlineUserCount() %> 人</p>
                                <p class="detail">在线用户</p>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>

        <div class="row-fluid">
            <div class="block span6">
                <a href="#serviceInfo" class="block-heading" data-toggle="collapse">服务器信息</a>
                <div id="serviceInfo" class="block-body collapse in">
                    <div style="margin-top:20px;margin-bottom:20px;">
                        <span>内存使用:(共:<%=SystemInfoUtil.getMemeryInfo()[0] / 1024 %> MB)</span>
                        <div class="progress" style="margin-bottom:0px;">
                            <div class="progress-bar" aria-valuemin="0" aria-valuemax="100" style="
                                    width: <%=SystemInfoUtil.getMemeryPercent() %>;background-color: #337ab7;color:#fff;text-align:center;">
                                <%=SystemInfoUtil.getMemeryPercent() %>
                            </div>
                        </div>
                    </div>
                    <div style="margin-top:20px;margin-bottom:20px;">
                        <%
                            String panfu = RequestUtil.getRealPath().substring(0, 1);
                            if (panfu == null || panfu.equals("")) {
                                panfu = "C";
                            }
                            Map<String, String[]> map = SystemInfoUtil.getDisk();
                            if (map == null) {
                                map = new HashMap<String, String[]>();
                            }
                            String[] panxinxi = map.get(panfu);
                            String maxsize;
                            String baifengbi;
                            if (panxinxi == null) {
                                maxsize = "----";
                                baifengbi = "0%";
                            } else {
                                Long maxsizenum = Long.valueOf(panxinxi[0]) / 1024;
                                maxsize = String.valueOf(maxsizenum);
                                baifengbi = panxinxi[3];
                            }
                        %>
                        <span>磁盘使用:(<%=panfu %>:/共<%=maxsize %>MB)</span>
                        <div class="progress" style="margin-bottom:0px;">
                            <div class="progress-bar" aria-valuemin="0" aria-valuemax="100" style="
                                    width: <%=baifengbi %>;
                                    background-color: #5bc0de;color:#fff;text-align:center;">
                                <%=baifengbi %>
                            </div>
                        </div>
                    </div>
                    <%
                        String memerypercent = SystemInfoUtil.getMemeryPercent();
                        memerypercent = memerypercent.substring(0, memerypercent.length() - 1);
                        String jvmmemerypercent = SystemInfoUtil.getJVMMemeryPercent();
                        jvmmemerypercent = jvmmemerypercent.substring(0, jvmmemerypercent.length() - 1);
                    %>
                    <div class="prg-cont rad-prg" id="indicatorContainer1"
                         style="width:33.3%;float:left;text-align: center;">
                        <script type="text/javascript">
                            var radialObj1 = radialIndicator('#indicatorContainer1', {
                                barColor: ' #337ab7',
                                barWidth: 10,
                                initValue: 0,
                                roundCorner: true,
                                percentage: true
                            });
                            radialObj1.animate(<%=memerypercent %>);
                        </script>
                        <br>
                        <span style="text-align:center;width:100%;">内存使用</span>
                    </div>
                    <div class="prg-cont rad-prg" id="indicatorContainer2"
                         style="width:33.3%;float:left;text-align: center;">
                        <script type="text/javascript">
                            var radialObj2 = radialIndicator('#indicatorContainer2', {
                                barColor: '  #5bc0de',
                                barWidth: 10,
                                initValue: 0,
                                roundCorner: true,
                                percentage: true
                            });
                            radialObj2.animate(<%=baifengbi.substring(0,baifengbi.length()-1) %>);
                        </script>
                        <br>
                        <span style="text-align:center;width:100%;">磁盘使用</span>
                    </div>
                    <div class="prg-cont rad-prg" id="indicatorContainer3"
                         style="width:33.3%;float:left;text-align: center;">
                        <script type="text/javascript">
                            var radialObj3 = radialIndicator('#indicatorContainer3', {
                                barColor: ' #5cb85c',
                                barWidth: 10,
                                initValue: 0,
                                roundCorner: true,
                                percentage: true
                            });
                            radialObj3.animate(<%=jvmmemerypercent %>);
                        </script>
                        <br>
                        <span style="text-align:center;width:100%;">JVM内存</span>
                    </div>
                </div>
            </div>

            <div class="block span6">
                <a href="#widget0container" class="block-heading" data-toggle="collapse">一周访问量统计</a>
                <div id="widget0container" class="block-body collapse in">
                    <canvas id="fangwenliangChart" width="500px;" height="278px">您的浏览器不支持显示图表</canvas>
                </div>
            </div>
        </div>
        <div class="row-fluid">
            <div class="block span6">
                <a href="#adminLogininfo" class="block-heading" data-toggle="collapse">管理员登录记录<span
                        class="label label-warning">+0</span></a>
                <div id="adminLogininfo" class="block-body collapse in">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>姓名</th>
                            <th>用户名</th>
                            <th>时间</th>
                        </tr>
                        </thead>
                        <tbody id="userlisttbody">
                        </tbody>
                    </table>
                    <p><a href="javascript:window.parent.selectOk('usersList');">更多...</a></p>
                </div>
            </div>
            <div class="block span6">
                <a href="#widget1container" class="block-heading" data-toggle="collapse">网站详细信息 </a>
                <div id="widget1container" class="block-body collapse in">
                    <h2>介绍：</h2>
                    <p><%=WebsiteInfo.getWebsiteName()%>
                    </p>
                    <p><%=WebsiteInfo.getDescription() %>
                    </p>
                    <p></p>
                </div>
            </div>
        </div>
        <div class="row-fluid">
            <div class="block span6">
                <div class="block-heading">
            <span class="block-icon pull-right">
                <a href="#" class="demo-cancel-click" rel="tooltip" title="刷新"><i class="icon-refresh"></i></a>
            </span>

                    <a href="#widget2container" data-toggle="collapse">预留portal</a>
                </div>
                <div id="widget2container" class="block-body collapse in">
                    <table class="table list">
                        <tbody>
                        <tr>
                            <td>
                                <p><i class="icon-user"></i> portal</p>
                            </td>
                            <td>
                                <p>portal</p>
                            </td>
                            <td>
                                <p>日期: 7/19/2012</p>
                                <a href="#">portal</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="block span6">
                <p class="block-heading">预留portal</p>
                <div class="block-body">
                    <h2>Built with Less</h2>
                    <p>The CSS is built with Less. There is a compiled version included if you prefer plain CSS.</p>
                    <p>Fava bean jícama seakale beetroot courgette shallot amaranth pea garbanzo carrot radicchio peanut
                        leek pea sprouts arugula brussels sprout green bean. Spring onion broccoli chicory shallot
                        winter purslane pumpkin gumbo cabbage squash beet greens lettuce celery. Gram zucchini swiss
                        chard mustard burdock radish brussels sprout groundnut. Asparagus horseradish beet greens
                        broccoli brussels.</p>
                    <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
                </div>
            </div>
        </div>
        <footer>
            <hr>

            <!-- Purchase a site license to remove this link from the footer: http://www.portnine.com/bootstrap-themes -->
            <p class="pull-right">A <a href="#"><%=ProjectInfo.getCompanyName() %>
            </a> by <a href="#" title="后台管理系统"><%=ProjectInfo.getCompanyName() %>
            </a></p>

            <p>&copy; 2016 <a href="#" title="后台管理系统" target="_blank"><%=ProjectInfo.getCompanyName() %>
            </a></p>
        </footer>
    </div>
</div>
<script src="static/js/jquery1-11-3.min.js" type="text/javascript"></script>
<script src="static/admin/lib/bootstrap/js/bootstrap.js"></script>
<script src="static/admin/js/bootstrap-closable-tab.js"></script>
<script type="text/javascript" src="static/admin/lib/chart/Chart.min.js"></script>
<script type="text/javascript">
    $(function () {
        refMessageandCount();
        refUserList();
        window.setInterval("refMessageandCount()", 30000); //每30秒刷新一次消息
        window.setInterval("refUserList()", 300000); //每300秒刷新一次用户登录信息
        weekVisitorVolume();//显示图表
    });
    function refMessageandCount() {
        $.ajax({
            type: "get",
            url: "admin/prompt",
            data: {},
            success: function (result) {
                if (result.data.content == "" || result.data.content == "null") {
                    $("#prompt").text("信息获取失败!");
                } else {
                    $("#prompt").text(result.data.content);
                }
            }
        });
    }
    function refUserList() {
        $.ajax({
            type: "get",
            url: "admin/website/userListDom",
            data: {count: 5},
            success: function (result) {
                $("#userlisttbody").text("");
                if (result.data == "" || result.data == "null") {
                    $("#userlisttbody").text("信息获取失败!");
                } else {
                    $("#userlisttbody").append(result.data);
                }
            }
        });
    }

    function weekVisitorVolume() {
        $.ajax({
            type: "get",
            url: "admin/website/weekVisitorVolume", ////////
            data: {},
            success: function (result) {
                if (result.data == "" || result.data == "null") {
                    showWeekVisiChar("0");
                } else {
                    showWeekVisiChar(result.data);
                }
            }
        });
    }
    function showWeekVisiChar(str) {
        //初始化图表
        //数据结构
        var myDate = new Date(); //获取今天日期
        myDate.setDate(myDate.getDate() - 6);
        var datelist = [];
        var dateTemp;
        var flag = 1;
        for (var i = 0; i < 7; i++) {
            dateTemp = (myDate.getMonth() + 1) + "月" + myDate.getDate() + "日";
            datelist.push(dateTemp);
            myDate.setDate(myDate.getDate() + flag);
        }
        var dataArray = str.split(",");//[10,20,30,40,50,60,70];
        var data = {
            labels: datelist,//["January","February","March","April","前天","昨天","今天"],
            datasets: [
                {
                    fillColor: "rgba(151,187,205,0.5)",
                    strokeColor: "rgba(151,187,205,1)",
                    data: dataArray
                }
            ]
        };
        var ctx = document.getElementById("fangwenliangChart").getContext("2d");
        new Chart(ctx).Bar(data);//显示成图表
    }
</script>
</body>
</html>
